#include "lcd_display.h"

#include "lcd.h"

/**
 * @brief lcd 初始化
 *
 */
void lcd_display_init(void)
{
    lcd_init(3);
    lcd_fill(0, 0, g_lcd_size.w, g_lcd_size.h, LCD_WHITE);
}

/**
 * @brief 加载ui
 *
 */
void lcd_load_ui(void)
{
    lcd_show(64, 17, "航天航空模型", LCD_RED, LCD_WHITE, 32);
    lcd_draw_line(0, 64, g_lcd_size.w, 64, LCD_BLACK);
    lcd_show(5, 82, "烟雾浓度", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(69, 82, ": ", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(133, 82, "ppm", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(184, 82, "温度", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(216, 82, ": ", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(304, 82, "℃", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(5, 108, "湿度", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(37, 108, ": ", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(133, 108, "%", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(184, 108, "UV", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(200, 108, "等级", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(232, 108, ": ", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(304, 108, "级", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(5, 134, "CO2", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(29, 134, "浓度", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(61, 134, ": ", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(133, 134, "ppm", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(184, 134, "O2", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(200, 134, "浓度", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(232, 134, ": ", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(304, 134, "%", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(5, 160, "火焰监测", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(69, 160, ": ", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(184, 160, "电量", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(216, 160, ": ", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(304, 160, "%", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(5, 186, "噪声监测", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(69, 186, ": ", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(184, 186, "重力监测", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(248, 186, ": ", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(5, 212, "IP", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(21, 212, "地址", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(53, 212, ": ", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(184, 212, "端口", LCD_BLACK, LCD_WHITE, 16);
    lcd_show(216, 212, ": ", LCD_BLACK, LCD_WHITE, 16);
}

/**
 * @brief 设置烟感显示值
 *
 * @param mq2_vale double 烟感值
 */
void lcd_set_mq2(double mq2_vale)
{
    uint8_t buf[50] = {0};

    sprintf(buf, "%.2f ", mq2_vale);

    lcd_show(77, 82, buf, LCD_BLUE, LCD_WHITE, 16);
}

/**
 * @brief 设置温度显示值
 *
 * @param temperature double 温度
 */
void lcd_set_temperature(double temperature)
{
    uint8_t buf[50] = {0};

    sprintf(buf, "%.2f ", temperature);

    lcd_show(256, 82, buf, LCD_BLUE, LCD_WHITE, 16);
}

/**
 * @brief 设置湿度显示值
 *
 * @param humidity double 湿度
 */
void lcd_set_humidity(double humidity)
{
    uint8_t buf[50] = {0};

    sprintf(buf, " %.2f ", humidity);

    lcd_show(69, 108, buf, LCD_BLUE, LCD_WHITE, 16);
}

/**
 * @brief 设置紫外线等级显示值
 *
 * @param uv_index uv_index_e 紫外线等级
 */
void lcd_set_uv_index(uv_index_e uv_index)
{
    uint8_t buf[50] = {0};

    sprintf(buf, "%d ", uv_index);

    lcd_show(256, 108, buf, LCD_BLUE, LCD_WHITE, 16);
}

/**
 * @brief 设置二氧化碳显示值
 *
 * @param co2_value uint16_t 二氧化碳浓度
 */
void lcd_set_co2(uint16_t co2_value)
{
    uint8_t buf[50] = {0};

    sprintf(buf, " %d ", co2_value);

    lcd_show(69, 134, buf, LCD_BLUE, LCD_WHITE, 16);
}

/**
 * @brief 设置氧气显示值
 *
 * @param co2_value double 氧气浓度
 */
void lcd_set_o2(double co2_value)
{
    uint8_t buf[50] = {0};

    sprintf(buf, "%.2f ", co2_value);

    lcd_show(256, 134, buf, LCD_BLUE, LCD_WHITE, 16);
}

/**
 * @brief 设置噪声监测显示值
 *
 * @param noise_state bool 噪声监测
 */
void lcd_set_noise(bool noise_state)
{
    if (noise_state)
    {
        lcd_show(77, 186, "超标", LCD_BLUE, LCD_WHITE, 16);
    }
    else
    {
        lcd_show(77, 186, "正常", LCD_BLUE, LCD_WHITE, 16);
    }
}

/**
 * @brief 设置重力监测显示值
 *
 * @param gravity_state bool 重力监测
 */
void lcd_set_gravity(bool gravity_state)
{
    if (!gravity_state)
    {
        lcd_show(256, 186, "正常", LCD_BLUE, LCD_WHITE, 16);
    }
    else
    {
        lcd_show(256, 186, "超标", LCD_BLUE, LCD_WHITE, 16);
    }
}

/**
 * @brief 设置ip显示值
 *
 * @param ip uint32_t ip
 */
void lcd_set_ip(uint32_t ip)
{
    uint8_t buf[50] = {0};

    sprintf(buf, "%s ", inet_ntoa(ip));

    lcd_show(69, 212, buf, LCD_BLUE, LCD_WHITE, 16);
}

/**
 * @brief 设置port显示值
 *
 * @param port uint32_t port
 */
void lcd_set_port(uint32_t port)
{
    uint8_t buf[50] = {0};

    sprintf(buf, "%d ", port);

    lcd_show(256, 212, buf, LCD_BLUE, LCD_WHITE, 16);
}

/**
 * @brief 设置电池显示值
 *
 * @param battery double 电池电量
 */
void lcd_set_battery(double battery)
{
    uint8_t buf[50] = {0};

    sprintf(buf, "%d ", (uint8_t)battery);

    lcd_show(256, 160, buf, LCD_BLUE, LCD_WHITE, 16);
}

/**
 * @brief 设置火焰监测显示值
 *
 * @param fire_state bool 火焰监测
 */
void lcd_set_fire(bool fire_state)
{
    if (fire_state)
    {
        lcd_show(77, 160, "超标", LCD_BLUE, LCD_WHITE, 16);
    }
    else
    {
        lcd_show(77, 160, "正常", LCD_BLUE, LCD_WHITE, 16);
    }
}
